package com.itheima.tanhua.service;

import com.itheima.tanhua.api.mongo.CommentApi;
import com.itheima.tanhua.enums.CommentType;
import com.itheima.tanhua.interceptor.userHolder;
import com.itheima.tanhua.pojo.mongo.Comment;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;

/**
 * @author 芝士雪豹
 * @create 2022/9/25/17:21
 */
public class CommentService {
    @DubboReference
    private CommentApi commentApi;

    public void saveComments(String movementId, String comment) {
        //获取当前登陆者id
        Long userId = userHolder.getId();
        //创建互动表对象
        Comment comments = new Comment();
        comments.setCommentType(CommentType.COMMENT.getType());
        comments.setUserId(userId);
        comments.setContent(comment);
        comments.setPublishId(new ObjectId(movementId));
        comments.setCreated(System.currentTimeMillis());
        Integer commentCount = commentApi.saveComments(comments);

    }
}
